package logic

import (
	"context"
	"shop_srv/shopsrvclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsPushLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsPushLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsPushLogic {
	return &GoodsPushLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsPushLogic) GoodsPush(req *types.GoodsPushRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	push, err := l.svcCtx.ShopSrv.GoodsPush(l.ctx, &shopsrvclient.GoodsPushRequest{
		Name:   req.Name,
		Price:  req.Price,
		Stock:  req.Stock,
		Max:    req.Max,
		UserId: int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品添加成功",
		Data:    push,
	}, nil
}
